package trans.support;

import java.util.Map;

import trans.model.User;
import trans.service.SADAO;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class AuthenticationInterceptor implements Interceptor  {

	private static final long serialVersionUID = 1L;

	public void destroy () {}

    public void init() {}

    public String intercept(ActionInvocation actionInvocation) throws Exception {

        @SuppressWarnings("rawtypes")
		Map session = actionInvocation.getInvocationContext().getSession();

        User user = (User) session.get(Constants.USER_KEY);
        
        if (user == null) {
            return "index";            
        }else {
        	 if(user.getIsCustomer()){
        		 user.setHandedSa(SADAO.getSaCountByHandStatus(user.getId(), Constants.STATUS_SA_HANDED));
        	 }else{
        		 user.setNeedHandSa(SADAO.getSaCountByHandStatus(null, Constants.STATUS_SA_NEEDHAND));
        	 }
            return actionInvocation.invoke();
        }
    }

}
